package com.task.web.controller.core;

import javax.annotation.Resource;

import com.task.core.vo.resp.EngineSchemeDetailRespVo;
import com.task.core.vo.resp.FlowFilterDetailRespVo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.task.common.annotation.Log;
import com.task.common.core.controller.BaseController;
import com.task.common.core.domain.AjaxResult;
import com.task.common.core.page.TableDataInfo;
import com.task.common.enums.BusinessType;
import com.task.common.utils.SecurityUtils;
import com.task.core.dto.request.FlowFilterRequestDTO;
import com.task.core.service.CheckService;
import com.task.core.service.FlowFilterService;

import io.swagger.annotations.Api;

/**
 * @author 迪迦.
 * @date 2024/11/4 14:30
 */
@Api("")
@RestController
@RequestMapping("/flowFilter")
public class FlowFilterController extends BaseController {


  @Resource
  private FlowFilterService flowFilterService;

  @Resource
  private CheckService checkService;


  @PreAuthorize("@ss.hasPermi('flowFilter:list')")
  @GetMapping("/getFlowFilterByPage")
  public TableDataInfo getFlowFilterByPage(FlowFilterRequestDTO request) {
    startPage(request.getPageNum(), request.getPageSize());
    return getDataTable(flowFilterService.getFlowFilterByPage(request));
  }


  @PreAuthorize("@ss.hasPermi('flowFilter:option')")
  @GetMapping("/getFlowFilterByPageInMissionDetail")
  public TableDataInfo getFlowFilterByPageInMissionDetail(FlowFilterRequestDTO request) {
    startPage(request.getPageNum(), request.getPageSize());
    return getDataTable(flowFilterService.getFlowFilterByPageInMissionDetail(request));
  }


  @PreAuthorize("@ss.hasPermi('flowFilter:option')")
  @GetMapping("/getFlowFilterForOption")
  public TableDataInfo getFlowFilterForOption(FlowFilterRequestDTO request) {
    return getDataTable(flowFilterService.getFlowFilterForOption(request));
  }

  @Log(title = "流量管理", businessType = BusinessType.INSERT)
  @PostMapping("/addFlowFilter")
  public AjaxResult addFlowFilter(@RequestBody FlowFilterRequestDTO request) {
    request.setOperationBy(SecurityUtils.getLoginUser().getUserId());
    flowFilterService.addFlowFilter(request);
    return success();
  }

  @Log(title = "流量管理", businessType = BusinessType.UPDATE)
  @PutMapping("/modifyFlowFilter")
  public AjaxResult modifyFlowFilter(@RequestBody FlowFilterRequestDTO request) {
    checkService.check("data_flow_filter", request.getCode());
    request.setOperationBy(SecurityUtils.getLoginUser().getUserId());
    flowFilterService.modifyFlowFilter(request);
    return success();
  }

  @Log(title = "流量管理", businessType = BusinessType.DELETE)
  @DeleteMapping("/deleteFlowFilter/{flowFilterCode}")
  public AjaxResult deleteFlowFilter(@PathVariable String flowFilterCode) {
    checkService.check("data_flow_filter", flowFilterCode);
    flowFilterService.deleteFlowFilter(flowFilterCode, SecurityUtils.getLoginUser().getUserId());
    return success();
  }

  @GetMapping ("/getFlowFilterDetail/{flowFilterCode}")
  @PreAuthorize("@ss.hasPermi('system:flowFilter:edit')")
  public AjaxResult getFlowFilterDetail(@PathVariable String flowFilterCode) {
    checkService.check("data_flow_filter", flowFilterCode);
    FlowFilterDetailRespVo flowFilterDetail  = flowFilterService.getFlowFilterDetail(flowFilterCode);
    return success(flowFilterDetail);
  }
}
